package com.soft.config;

import com.soft.interceptor.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Locale;

//扩展SpringMVC, 扩展看需要实现的方法
@Configuration
public class MyMVCConfig implements WebMvcConfigurer {

    @Bean
    public ViewResolver myViewResolver(){
        return new MyViewResolver();
    }
    //重修方法实现拦截器，视图解析器等
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController( "/gyx" ).setViewName( "test" );
        registry.addViewController("/index").setViewName("index");
//        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/index2").setViewName("index-two");
    }

    public class MyViewResolver implements ViewResolver{
        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {
            return null;
        }
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**").
                excludePathPatterns("index", "/user/login", "/js/**","/css/**", "/img/**", "/fonts/**");
    }
}
